package youleche.com.controler.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import youleche.com.business.BVehicleInfo;
import youleche.com.controler.servlet.common.UlecheHttpServlet;
import youleche.com.model.MVehicleInfo;
import youleche.com.util.JsonHelper;

/**
 * Servlet implementation class SearchServlet
 */
public class CSearchServlet extends UlecheHttpServlet {
	private static final long serialVersionUID = 1L;
       
	/**
	 * 房屋信息处理
	 */
	//private BHouseInfo houseInfoBusi = null;
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CSearchServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		//先从缓存中加载数据，然后再从数据库中加载数据
		String searchValue = request.getParameter("v");
		if(!"".equals(searchValue)){
			int pageSize = Integer.parseInt(request.getParameter("pageSize"));
			Integer startIndex = (Integer.parseInt(request.getParameter("pageIndex")) - 1) * pageSize ;
			BVehicleInfo handler = new BVehicleInfo();
			try {
				List<MVehicleInfo> list = handler.getVehicleInfoListBySearch(startIndex.toString(), ((Integer) pageSize).toString(), searchValue);
				if(list != null && list.size() > 0){
					JsonHelper.printListToJsonString(response, list);
					return;
				}				

				super.response(response, "");
			} catch (Exception e) {
				super.response(response, "");
				e.printStackTrace();
			}
		}
		
	}

}
